//
//  CellConfigurator.swift
//  Automobile
//
//  Created by erkebulan elzhan on 7/22/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit

protocol ConfigurableCell {
    associatedtype DataType
    func configure(data: DataType, index: Int)
    func returnData() -> DataType
}
protocol CellConfigurator {
    static var reuseId: String { get }
    func configure(cell: UIView, index: Int)
    func returnData(cell: UIView) -> Any
}

class TableCellConfigurator<CellType: ConfigurableCell, DataType> : CellConfigurator where CellType.DataType == DataType, CellType: UITableViewCell {
    static var reuseId: String { return String(describing: CellType.self) }
    var item: DataType
    init(item: DataType) {
        self.item = item
    }
    func configure(cell: UIView, index: Int) {
        (cell as! CellType).configure(data: item, index: index)
    }
    func returnData (cell: UIView) -> Any {
        (cell as! CellType).returnData() as! Any
    }
}
